
function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
     }
     catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}
 
var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object
 
function ajaxFunction() {
  var getdate = new Date();  //Used to prevent caching during ajax call
  if(xmlhttp) { 
    xmlhttp.open("GET","gettime?" + getdate.getTime(),true); //gettime will be the servlet name
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);
  }
}
 
function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
       document.myForm.time.value=xmlhttp.responseText; //Update the HTML Form element 
     }
     else {
        alert("Esperar un momento por favor");
     }
   }
}

function cambiar_imagen(){
    
    
}

window.onload = function() {           
    var pic=document.getElementById('granja').getElementsByTagName('img');  
    //document.getElementById('granja').getElementsByTagName('img').onclick = getTime;
    for(c=0;c<pic.length;c++) {            
        pic[c].onclick=function() {
            num1=parseFloat(this.id.split('cuadro')[1]);
                //this.src=imgs[num1+3];
                //document.getElementById('granja').className='bg'+num1;
                for(c=0;c<pic.length;c++) {
                    num0=parseFloat(pic[c].id.split('cuadro')[1]);
                    if(pic[c].id==this.id) {                      
                        pic[c].src="imagenes/puerquito.jpg";                        
                        ajaxFunction();
                    }
                }
         
        }
    }
//	getTime();
//	document.getElementById("getTimeButton").onclick = getTime;
}

            function delayer(){
                            window.location = "inicio.jsp"
                        }